﻿<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ page session="true" %>
        <!DOCTYPE html>
        <html lang="en">

        <head>
            <meta charset="UTF-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=1600, initial-scale=1.0">
            <link rel="stylesheet" href="icofont/css/all.css">
            <link rel="stylesheet" href="css/common.css">
            <link rel="stylesheet" href="css/user.css">
            <link rel="shortcut icon" href="images/favicon.ico">
            <title>搜索问卷</title>
        </head>

        <body>
            <div class="nav">
                <a href="#"><img src="images/logo.png" width="130" height="48"></a>
                <ul>
                    <li><a href="/query/manager"><span class="fas font">&#xf21b;</span>管理员入口</a></li>
                    <li><a href="/query/user/search"><span class="fas font">&#xf7f2;</span>我的问卷</a></li>
                    <li>
                        <div class="usr">
                            <span class="fas font">&#xf508;</span>${user.userName}
                            <div class="choice">
                                <span class="fas font"><a href="/query/user">&#xf02d;用户信息</a></span>
                                <p class="line"></p>
                                <span class="fas font"><a href="/query/logout">&#xf14d;退出登录</a></span>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div>
                <div class="menu">
                    <span><a href="/query/user/addQuery">+创建问卷</a></span>
                    <span class="fas font"><a href="/query/user/search">&#xf002;&nbsp;&nbsp;搜索问卷</a></span>
                    <span class="fas font"><a href="/query/user/updatePassword">&#xf084;&nbsp;&nbsp;修改密码</a></span>
                    <span class="fas font"><a href="/query/user">&#xf2c2;&nbsp;&nbsp;用户信息</a></span>
                    <span class="fas font"><a href="/query/logout">&#xf14d;&nbsp;&nbsp;退出登录</a></span>
                </div>
                <div class="content">
                    <div class="title">
                        <span class="fas font">&#xf002;&nbsp;&nbsp;问卷列表</span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;搜索问卷:
                        <input type="text" id="title" value="" placeholder="问卷标题" name="keywords" class="common-text" maxlength="16">
                        <input type="button" id="search" value="搜索" class="btn btn-primary btn2">
                    </div>
                    <div class="querys">
                        <c:forEach items="${queryList}" var="query">
                            <div class="shadow">
                                <div class="info">
                                    <h4>${query.title}</h4>
                                    <span>${query.submitTime}</span>
                                    <span>发布人:${query.account}</span>
                                    <c:choose>
                                        <c:when test="${query.close eq false }">
                                            <span>已发布</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span>已停止</span>
                                        </c:otherwise>
                                    </c:choose>
                                    <span>ID:${query.id}</span>
                                </div>
                                <div class="operator">
                                    <span class="fas font"><a href="/query/${query.id}" title="问卷链接" target="_blank">&#xf0c1;</a></span>
                                    <c:choose>
                                        <c:when test="${query.close eq false }">
                                            <span class="fas font"><a href="/query/user/close/${query.id}/1">&#xf28b;停止问卷</a></span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="fas font"><a href="/query/user/close/${query.id}/0">&#xf144;继续问卷</a></span>
                                        </c:otherwise>
                                    </c:choose>
                                    <span class="fas font"><a href="/query/user/delete/${query.id}">&#xf2ed;删除问卷</a></span>
                                    <span class="fas font"><a href="/query/user/questions/${query.id}">&#xf002;查看问卷</a></span>
                                </div>
                            </div>
                        </c:forEach>
                        <form class="goto-page" action="#" method="post">
                            <input type="button" name="prev" value="<" class="btn" onclick="gotoPage(1)">
                            <li>第</li>
                            <input type="text" id="page" value="${queryPage}" size="1" name="page" class="common-text">
                            <li>页</li>
                            <input type="button" name="next" value=">" class="btn" onclick="gotoPage(2)">
                            <input type="button" value="跳转" class="btn btn-primary" onclick="gotoPage(3)">
                        </form>
                        <p class="line"></p>
                    </div>
                </div>
            </div>
        </body>
        <script src="js/jquery-3.6.0.min.js"></script>
        <script>
            var page = $("#page").val();
            function gotoPage(choice) {
                var temp = page;
                if (choice == 1) {
                    temp--;
                } else if (choice == 2) {
                    temp++;
                } else {
                    temp = $("#page").val();
                }
                if (temp <= 0) {
                    alert("页码不能小于等于0!");
                } else {
                    $.ajax({
                        url: "/query/user/gotoPage",
                        type: "POST",
                        data: {
                            "page": temp
                        },
                        traditional: true,
                        success:function(result){
                            if(result=="true"){
                                location.reload();
                            }else{
                                alert("该页不存在!");
                            }
                        }
                    });
                }
            }
            $("#search").click(function(){
                var title = $("#title").val();
                console.log(title);
                var param = {"title":title};
                $.post("/query/user/search",param,function(result){
                    if(result=="true"){
                        location.reload();
                    }else{
                        alert("查询的问卷不存在!");
                    }
                });
            })
        </script>

        </html>